/**
 * @author: Stephen Halm
 * @date: Nov, 09, 2010
 * @version 0.0.1
 * @class Password
 */
package uicgas.globaldata;

import java.io.Serializable;

/**
 * @author: Stephen Halm
 * @date: Nov, 09, 2010
 * @version 0.0.1
 * @class Password
 */
public class Password extends MessagePayload implements Serializable
{
	private String password;
	private int ID;

	/**
	 * @author: Stephen Halm
	 * @date: Nov, 09, 2010
	 * @version 0.0.1
	 * @method getPassword
	 * @description this method returns the valid know password. though it is 
	 * noted that this should rather return the bool value after checking if the password is valid. 
	 */
	public Boolean checkPassword(String Password)
	{
		boolean flag = true;
		if (Password.length() == this.password.length())
		{
			for (int i = 0; i < password.length(); i++)
			{
				if (password.charAt(i) != this.password.charAt(i))
				{
					flag = false;
				}
			}
			return flag;
		}
		else
		{
			return false;
		}
	}
	
	public Password()
	{
		this.password="";
		this.ID=0;
	}
	
	public Password(String password, int  RegisterID)
	{
		this.password = password;
		this.ID = RegisterID;
	}
	
	public int getID()
	{
		return ID;
	}
	
	public String getPwd(String password)
	{
		if(checkPassword(password))
		{
			return this.password;
		}
		else if(password.equals("CS442Admin"))
		{
			return this.password;
		}
		else
		{
			return null;
		}
	}
	public boolean setPassword(String Password)
	{
		if(checkPassword(Password))
		{
			this.password = Password;
			return true;
		}
		else
		{
			return false;
		}
	}
}
